package org.bringer.webapp.services.impl;

import org.apache.tapestry5.ValueEncoder;
import org.bringer.model.Account;
import org.bringer.model.Annotation;
import org.bringer.service.AnnotationManager;


public class AnnotationEncoder implements ValueEncoder<Annotation> {

    private AnnotationManager annotationManager;

    public AnnotationEncoder(AnnotationManager annotationManager) {
        this.annotationManager = annotationManager;
    }

    public String toClient(Annotation value) {
        return value != null ? String.valueOf(value.getId()) : null;
    }

    public Annotation toValue(String id) {

        if (id == null || "null".equals(id)) {
            return null;
        }
        Annotation account = annotationManager.get(Long.parseLong(id));
     

        return account;
    }

}
